//
//  GoodAttributeListCell.m
//  ReceiptDelivery
//
//  Created by 吕晶 on 2020/9/22.
//  Copyright © 2020 吕晶. All rights reserved.
//

#import "GoodAttributeListCell.h"

@interface GoodAttributeListCell ()

@property (nonatomic, strong) UIView *bgView;
@property (nonatomic, strong) UILabel *titleLab;
@property (nonatomic, strong) UIButton *editBtn;
@property (nonatomic, strong) UILabel *contentLab;

@end

@implementation GoodAttributeListCell

+ (instancetype)GoodAttributeListCellWithTableView:(UITableView *)tableView {
    static NSString *cellID = @"GoodAttributeListCell";
    GoodAttributeListCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[GoodAttributeListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.backgroundColor = Color_backgroundColor;
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        self.bgView = [[UIView alloc] initWithFrame:CGRectMake(15, 10, ScreenW - 30, 105)];
        self.bgView.backgroundColor = HexColor(0xffffff);
        self.bgView.layer.masksToBounds = YES;
        self.bgView.layer.cornerRadius = 6;
        [self.contentView addSubview:self.bgView];
        
        self.titleLab = [UILabel new];
        self.titleLab.textColor = HexColor(0x2B2C44);
        self.titleLab.font = BoldFontOfSize(18);
        [self.bgView addSubview:self.titleLab];
        
        self.editBtn = [UIButton new];
        self.editBtn.backgroundColor = HexColorA(0xFBA962, 0.1);
        self.editBtn.layer.masksToBounds = YES;
        [self.editBtn setTitle:@"编辑模板" forState:0];
        self.editBtn.titleLabel.font = BoldFontOfSize(14);
        [self.editBtn setTitleColor:HexColor(0xFBA962) forState:0];
        [self.editBtn addTarget:self action:@selector(editClick) forControlEvents:UIControlEventTouchUpInside];
        [self.bgView addSubview:self.editBtn];
        
        self.contentLab = [UILabel new];
        self.contentLab.textColor = HexColor(0x9C9DB3);
        self.contentLab.font = [UIFont systemFontOfSize:14];
        self.contentLab.numberOfLines = 2;
        [self.bgView addSubview:self.contentLab];
        
        self.height = self.bgView.nim_bottom;
    }
    return self;
}

- (void)editClick {
    if (self.editBlock) {
        self.editBlock();
    }
}

-(void)setModel:(GoodAttributeListModel *)model {
    _model = model;
    [self configUI];
}

- (void)configUI {
    self.titleLab.text = self.model.title;
    [self.titleLab sizeToFit];
    self.titleLab.nim_left = 10;
    self.titleLab.nim_top = 15;
    
    self.editBtn.nim_width = 92;
    self.editBtn.nim_height = 30;
    self.editBtn.nim_left = self.bgView.nim_width - 10 - self.editBtn.nim_width;
    self.editBtn.nim_top = 13;
    self.editBtn.layer.cornerRadius = 15;
    
    self.titleLab.nim_width = self.editBtn.nim_left - 10 - self.titleLab.nim_left;
    
    self.contentLab.nim_left = 10;
    self.contentLab.nim_width = self.bgView.nim_width - 20;
    self.contentLab.text = self.model.names;
    [self.contentLab sizeToFit];
    self.contentLab.nim_top = (self.bgView.nim_height - self.titleLab.nim_bottom - self.contentLab.nim_height) * 0.5 + self.titleLab.nim_bottom;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
